import enum
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.types import Enum

from app.db.base import Base

class TransactionType(str, enum.Enum):
    RECHARGE = "RECHARGE"
    GENERATION_FEE = "GENERATION_FEE"
    REFUND = "REFUND"
    GIFT = "GIFT"

class CreditTransaction(Base):
    __tablename__ = "credit_transactions"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    amount = Column(Integer, nullable=False)
    type = Column(Enum(TransactionType), nullable=False)
    description = Column(String, nullable=True)
    related_job_id = Column(Integer, ForeignKey("generation_jobs.id"), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
